package com.smart_campus.campus.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smart_campus.campus.domain.CapumsNotice;
import com.smart_campus.campus.vo.CampusNoticeVo;
import com.smart_campus.sys.common.DataGridView;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

import com.smart_campus.campus.mapper.CapumsNoticeMapper;
import com.smart_campus.campus.service.CapumsNoticeService;

import java.util.List;

/**
 * @author Alfred
 * @time: 2020/6/29 8:58
 */
@Service
public class CapumsNoticeServiceImpl implements CapumsNoticeService {

    @Resource
    private CapumsNoticeMapper capumsNoticeMapper;

    //@CacheEvict 删除的注解通过对象id在redis中删除数据
    @CacheEvict(cacheNames = "com.smart_campus.campus.service.impl.CapumsNoticeServiceImpl",key = "#id")
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return capumsNoticeMapper.deleteByPrimaryKey(id);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.campus.service.impl.CapumsNoticeServiceImpl",key = "#result.id")
    @Override
    public CapumsNotice insert(CapumsNotice record) {
        capumsNoticeMapper.insert(record);
        return record;
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.campus.service.impl.CapumsNoticeServiceImpl",key = "#result.id")
    @Override
    public CapumsNotice insertSelective(CapumsNotice record) {
        capumsNoticeMapper.insertSelective(record);
        return record;
    }


    //@Cacheable 返回对象 通过对象id在redis中创建对象保存,方便下次使用
    @Cacheable(cacheNames ="com.smart_campus.campus.service.impl.CapumsNoticeServiceImpl",key = "#id")
    @Override
    public CapumsNotice selectByPrimaryKey(Integer id) {
        return capumsNoticeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(CapumsNotice record) {
        return capumsNoticeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(CapumsNotice record) {
        return capumsNoticeMapper.updateByPrimaryKey(record);
    }

    @Override
    public DataGridView queryNotice(CampusNoticeVo campusNoticeVo) {
        Page<Object> page = PageHelper.startPage(campusNoticeVo.getPage(), campusNoticeVo.getLimit());
        List<CampusNoticeVo> capumsNotices = this.capumsNoticeMapper.queryNotice(campusNoticeVo);
        return new DataGridView(page.getTotal(), capumsNotices);
    }

    @Override
    public Integer queryMax() {
        return this.capumsNoticeMapper.queryMax();
    }

    @Override
    public DataGridView getAllNotice() {
        List<CapumsNotice> capumsNotices = this.capumsNoticeMapper.getAllNotice();
        return new DataGridView(capumsNotices);
    }



}







